package com.easyweb.session;

import com.easyweb.entity.*;

import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityQuery;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.persistence.EntityManager;

@Name("illerList")
public class IllerList extends EntityQuery<Iller> {

	@In EntityManager entityManager;
	private static final String EJBQL = "select iller from Iller iller";
	private List<Iller> illerList=null;
	
	private static final String[] RESTRICTIONS = {
			"lower(iller.ilAdi) like lower(concat(#{illerList.iller.ilAdi},'%'))",
			"lower(iller.plakaKodu) like lower(concat(#{illerList.iller.plakaKodu},'%'))", };

	private Iller iller = new Iller();

	public IllerList() {
		setEjbql(EJBQL);
		setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS));
		setMaxResults(25);
	}

	public void illerListOlustur(){
		illerList=new ArrayList<Iller>();
		illerList=entityManager.createNamedQuery("illerTumKayitlar").getResultList();
	}
	
	public Iller getIller() {
		return iller;
	}

	public List<Iller> getIllerList() {
		if (illerList==null) illerListOlustur();
		return illerList;
	}

	public void setIllerList(List<Iller> illerList) {
		this.illerList = illerList;
	}
}
